function [sj_out, p_out, tax_s] = new_eq_CT_2(p_ini2,mc_update,theta2,ns,ind_market,x2,sales_tax, delta, A1, QI,year,FC,total_market,tier2,cat2,UVT,sc,tariffs)
sel_mrkt=ind_market(year>=2019);
% 
options = optimset('Display','iter-detailed' ,'Algorithm','sqp','GradObj', ...
'off','GradCon','off','DerivativeCheck','off', 'maxiter', 4000,...
'MaxFunEvals', 1000000,'TolFun',1e-08,'TolX',1e-8);

ctt=0.5;
v_c=getranddraw(length(theta2)-1, ns);
p_out=p_ini2;
expmu1=expmu(theta2,v_c,x2,p_out);
sj_out=mktshares(delta,expmu1,QI,ind_market);
tax_s=zeros(max(sel_mrkt),1);


parfor ii=min(sel_mrkt):max(sel_mrkt)
    ii
    temp=find(ind_market==ii);
    ind_market_i=ind_market(temp);
    delta_i=delta(temp);
    mc_i=mc_update(temp);
    p_nt_i=p_ini2(temp);
    A1_i=A1(temp,temp);
    x2_i=x2(temp,:);
    mrks_i=repmat(total_market(ii),length(temp),1);
    QI_i=QI(temp,:);
    
    cf_salestax_i=sales_tax(temp,:);
    cat_i=cat2(temp,:);
    tier_i=tier2(temp,:);
    tariff_i=tariffs(temp,:);
    FC_i=FC(temp,sc);
    ini_var=[ctt;p_nt_i];
    
    lb=[-inf; 0*ones(length(ini_var)-1,1)];%lower bound for price and import tariff
    ub=[5; inf*ones(length(ini_var)-1,1)]; %upper bound for proce and import tariff
    
    tic
    [out_1,ffval]=fmincon(@(ini)new_sj_CT(ini,delta_i,x2_i,theta2,v_c,cf_salestax_i,tier_i,cat_i,FC_i,mc_i,A1_i,mrks_i,UVT,tariff_i),ini_var,[], [], [], [], ...
    [lb],[ub],[], options);
    toc
    
    cat_new=cat_i.*out_1(1)* UVT;
    p_out_i=(out_1(2:end).*((1+cf_salestax_i+tier_i)))+(cat_new./1000);
    expmu1=expmu(theta2,v_c,x2_i,p_out_i);
    s_indiv=ind_shares(exp(delta_i),expmu1); 
    sj_cf=mean(s_indiv,2);
    price1=((mc_i+markup_sim(theta2,v_c,delta_i,s_indiv,A1_i,sj_cf)).*((1+cf_salestax_i+tier_i)))+(cat_new./1000);
    expmu2 = expmu(theta2,v_c,x2_i,price1);
    sj_2=mktshares(delta_i,expmu2,QI_i,ind_market_i);
    
    s_2{ii}=sj_2
    p_2{ii}=price1;
    tx{ii}=out_1(1);
    
end

for jj=min(sel_mrkt):max(sel_mrkt)
    temp2=find(ind_market==jj);
    p_out(temp2)=p_2{jj};
    tax_s(jj)=tx{jj};
    sj_out(temp2)=s_2{jj};
end


end% function computing counterfactual price equilibrium  

